package org.infinitest.swingui;

import java.awt.Component;

import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JTree;
import javax.swing.tree.DefaultTreeCellRenderer;

/**
 * @author <a href="mailto:benrady@gmail.com"Ben Rady</a>
 */
class FailureCellRenderer extends DefaultTreeCellRenderer
{
  public FailureCellRenderer()
  {
    setToolTipText("Double-click test nodes for more info");
  }

  @Override
  public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus)
  {
    JLabel label = (JLabel) super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
    label.setIcon(loadIcon(value));
    return label;
  }

  private static Icon loadIcon(Object node)
  {
    if (node instanceof String)
      return new ImageIcon(FailureCellRenderer.class.getResource("/org/infinitest/swingui/error.png"));
    return new ImageIcon(FailureCellRenderer.class.getResource("/org/infinitest/swingui/failure.png"));
  }

}
